package com.longshine.plc.ui;

import com.longshine.util.CommonUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import org.jdesktop.layout.GroupLayout;

public class ProtocolPanel extends OwnPanel
{
  private StringBuffer sb = new StringBuffer(10240);
  private JButton jButton2;
  private JScrollPane jScrollPane1;
  private JTextPane jTextPane1;

  public void init()
  {
    this.title = "报文";
    ActionListener l = new ActionListener()
    {
      public void actionPerformed(ActionEvent e) {
        String comm = e.getActionCommand();
        if (comm.equals("清空"))
          ProtocolPanel.this.clearMsg();
      }
    };
    this.jButton2.addActionListener(l);
  }

  public void clearMsg() {
    StringBuffer t = this.sb;
    this.sb = new StringBuffer(10240);
    t = null;
    this.jTextPane1.setText(this.sb.toString());
  }

  public void log(String str)
  {
    str = CommonUtil.getCurrentTime() + " " + str;
    System.out.println(str);
    this.sb.append(str + "\n");
    this.jTextPane1.setText(this.sb.toString());
  }

  public ProtocolPanel()
  {
    initComponents();
  }

  private void initComponents()
  {
    this.jScrollPane1 = new JScrollPane();
    this.jTextPane1 = new JTextPane();
    this.jButton2 = new JButton();

    this.jScrollPane1.setViewportView(this.jTextPane1);

    this.jButton2.setText("清空");

    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(1)
      .add(2, 
      layout.createSequentialGroup().add(this.jScrollPane1)
      .addContainerGap())
      .add(2, 
      layout.createSequentialGroup().add(0, 426, 32767)
      .add(this.jButton2)
      .add(71, 71, 71)));

    layout.setVerticalGroup(
      layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .addContainerGap()
      .add(this.jScrollPane1, -1, 401, 32767)
      .addPreferredGap(1)
      .add(this.jButton2)
      .add(20, 20, 20)));
  }
}